﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<title>项目管理列表</title>

<jsp:include page="/components/extjs/extjs.jsp" flush="false" />
<jsp:include page="/components/jquery/validate.jsp" flush="false" />
<script type="text/javascript" src="<c:url value="/components/jquery/jquery-1.5.1.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/main.js"/>"></script>
<jsp:include page="/components/My97DatePicker/DatePicker.jsp" flush="false" />

</head>
<body style="text-align: center">
	<form name="fom" id="fom" method="post" action="project_add.action">
		<s:actionmessage />
		<table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#464646" class="newfont03">
			<thead>
				<tr class="CTitle">
					<td height="22" colspan="2" align="center" style="font-size: 16px">项目信息添加</td>
				</tr>
			</thead>
			<tbody>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">项目名称</td>
					<td width="13%"><input type="text" name="proj.name" id="name" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">项目代码</td>
					<td width="13%"><input type="text" name="proj.proj_code" id="proj_code" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">项目类型</td>
					<td width="13%"><s:select list="%{types}" name="proj.typeid.id" listKey="id" listValue="name" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">承研部门</td>
					<td width="13%"><input type="text" name="proj.deptid.id" id="deptid" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">目标客户</td>
					<td width="13%"><input type="text" name="proj.proj_target" id="proj_target" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">立项时间</td>
					<td width="13%"><input type="text" name="proj.build_date" id="build_date" class="Wdate required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">开始时间</td>
					<td width="13%"><input type="text" name="proj.start_date" id="start_date" class="Wdate required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">结束时间</td>
					<td width="13%"><input type="text" name="proj.finish_date" id="finish_date" class="Wdate required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
				</tr>
				<!--
                <tr bgcolor="#EEEEEE" align="center">
                    <td width="2%">项目结题</td>
                    <td width="13%"><input type="text" name="proj.finish_date" id="finish_date"/></td>
                </tr>
                -->
				<tr bgcolor="#EEEEEE" align="center">
					<td width="2%">是否完成</td>
					<td width="13%"><s:select list="%{flags}" name="proj.proj_finished" listKey="scode" listValue="name" /></td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td colspan="2">项目人员</td>
				</tr>
				<tr bgcolor="#EEEEEE" align="center">
					<td colspan="2"><div id="grid" style="padding: 0px; margin: 0px; line-height: none; height: auto"></div></td>
				</tr>
				<tr>
					<td height="22" colspan="2" align="center" style="font-size: 16px"><input type="submit" value="提交" /></td>
				</tr>
			</tbody>
		</table>
	</form>
</body>
<script type="text/javascript">
	Ext
			.onReady(function() {

				Ext.QuickTips.init();
				var contextPath = "<%=path%>";
				Ext.BLANK_IMAGE_URL = contextPath + '/components/extjs/resources/images/default/s.gif';

				var store = new Ext.data.ArrayStore({
					fields : [ {
						name : 'name'
					}, {
						name : 'phone'
					}, {
						name : 'idno'
					}, {
						name : 'applyId'
					} ]
				});

				var grid = new Ext.grid.EditorGridPanel(
						{
							id : 'edgrid',
							store : store,
							columns : [
									{
										id : 'name',
										header : '姓名',
										width : 100,
										editor : new Ext.form.TextField({
											allowBlank : true
										}),
										dataIndex : 'name'
									},
									{
										header : '手机号码',
										width : 100,
										editor : new Ext.form.TextField({
											vtype : 'phoneOrMobile',
											vtypeText : "电话或者手机号码输入有误!",
											allowBlank : true
										}),
										dataIndex : 'phone'
									},
									{
										header : '身份证号码',
										width : 150,
										editor : new Ext.form.TextField({
											vtype : 'idcard',
											vtypeText : "身份证信息输入有误！",
											allowBlank : true
										}),
										dataIndex : 'idno'
									},
									{
										header : '操作',
										width : 40,
										renderer : function(value, metaData,
												record, rowIndex, colIndex,
												store) {
											return "<a href='#'><img src='"+contextPath+"/images/delete.png' alt='删除' title='点击删除该记录' onclick='removeRecord("
													+ rowIndex + ")'/></a>"
										}
									} ],
							stripeRows : true,
							height : 200,
							width : 480,
							border : true,
							clicksToEdit : 1,
							tbar : [ {
								text : '添加',
								iconCls : 'addIcon',
								handler : function() {

									var gridStore = grid.getStore();

									if (gridStore.getCount() > 0) {
										var index = 0;
										var phone = gridStore.getAt(index).get(
												'phone');
										var idno = gridStore.getAt(index).get(
												'idno');
										var name = gridStore.getAt(index).get(
												'name');

										if (!(phone || idno || name)) {
											Ext
													.getCmp('tbmsg')
													.setText(
															"<font color='red'>‘被调查人员’的‘手机号码’,‘姓名’,‘身份证号’至少有一项必填！</font>");
											return false;
										}
									}

									var Plant = gridStore.recordType;
									var p = new Plant({
										name : "",
										phone : "",
										idno : "",
										applyId : ""
									});
									grid.stopEditing();
									store.insert(0, p);
									grid.startEditing(0, 0);
								}
							} ],
							bbar : [ {
								xtype : 'tbtext',
								id : 'tipText',
								text : '操作提示:'
							}, '-', {
								xtype : 'tbtext',
								id : 'tbmsg',
								text : '单击单元格可编辑内容'
							} ],
							listeners : {
								'afteredit' : function(obj) {
									var gridStore = grid.getStore();
									if ('idno' == obj.field) {//开始去重
										for ( var i = 0; i < gridStore
												.getCount(); i++) {
											var idNoValue = gridStore.getAt(i)
													.get('idno');
											if ((obj.value == idNoValue)
													&& (obj.row != i)) {
												//1.提示“输入重复”的提示信息
												Ext.Msg
														.alert("系统提示",
																"当前涉案人员的身份证号码已经重复,请重新填写！");
												//2.将当前单元格置空
												gridStore.getAt(obj.row).set(
														"idno", "");
											}
										}
									}
									if ('phone' == obj.field) {//开始去重
										for ( var i = 0; i < gridStore
												.getCount(); i++) {
											var cellValue = gridStore.getAt(i)
													.get('phone');
											if ((obj.value == cellValue)
													&& (obj.row != i)) {
												//1.提示“输入重复”的提示信息
												Ext.Msg
														.alert("系统提示",
																"当前涉案人员的联系方式已经重复请重新填写！");
												//2.将当前单元格置空
												gridStore.getAt(obj.row).set(
														"phone", "");
											}
										}
									}

								}
							}
						});
				grid.render('grid');
			});

	/**
	 * 移除记录
	 */
	function removeRecord(index) {
		var store = Ext.getCmp("edgrid").store;
		store.removeAt(index);
	}
</script>
</html>